<?php
namespace app\index\controller;
use think\Controller;
use watch\open\Watch;
use think\Request;
use think\Session;
use think\Db;
class useradmin extends Controller
{
	public function user_list()
	{
                $page=Request::instance()->get('page');
                $limit=Request::instance()->get('limit');
                //搜索条件
                $username=Request::instance()->get('username');
                $telphone=Request::instance()->get('telphone');
                $email=Request::instance()->get('email');
                $map = array();
                $admin_user = array();
                if ($username!="") {
        			$map['username'] = ['like',"%$username%"];
                }
                if ($telphone!="") {
        			$map['telphone'] = ['like',"%$telphone%"];
                }
                if ($email!="") {
        			$map['email'] = ['like',"%$email%"];
                }
                $admin_user_arr=Db::table('admin_user')->where($map)->select();
                foreach ($admin_user_arr as $key => $value) {
                	$id=$value['id'];
                	$role=Db::table('auth_group_access')->field('group.id,group.title')
        			->alias('access')
        			->join('auth_group group','access.group_id = group.id')
        			->where('access.uid',$id)
        			->find();
                	$admin_user_arr[$key]['role']=$role;
                }
                //查询用户组
                $role=Request::instance()->get('role');
                if ($role!="") {
                	foreach ($admin_user_arr as $key => $value) {
                		if ($value['role']['id']==$role) {
                			$admin_user_arr[$key]['role']=$value['role']['title'];
                			$admin_user[]=$admin_user_arr[$key];
                		}
                	}
                }else{
                	foreach ($admin_user_arr as $key => $value) {
                		$admin_user_arr[$key]['role']=$value['role']['title'];
                	}
                	$admin_user=$admin_user_arr;
                }
                $this->result($admin_user,0,'获取成功');
	}

}
